package com.example.pmanagesys.config;
//配置类，用于将拦截器注册到 SpringBoot

import com.example.pmanagesys.interceptor.LoginCheckInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    private final LoginCheckInterceptor loginCheckInterceptor;

    // 构造函数 ，通过构造函数注入来将依赖项（如拦截器、服务等）传递给配置类。
    public WebMvcConfig(LoginCheckInterceptor loginCheckInterceptor) {
        this.loginCheckInterceptor = loginCheckInterceptor;
    }

    // 注册拦截器并指定拦截路径
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginCheckInterceptor)
                .addPathPatterns("/user/*") // 拦截/user路径下所有请求
                .addPathPatterns("/account/*")
                .addPathPatterns("/attendance/*")
                .addPathPatterns("/log/*")
                .addPathPatterns("/salary/*")
                .addPathPatterns("/")
                .excludePathPatterns("/user/login"); // 不拦截登录请求
    }
}

